package com.itheima.imclient100.utils;

import com.itheima.imclient100.view.BaseFragment;
import com.itheima.imclient100.view.ContactFragment;
import com.itheima.imclient100.view.ConversationFragment;
import com.itheima.imclient100.view.PluginFragment;

/**
 * Created by fullcircle on 2017/7/2.
 */

public class FragmentFactory {
    public static ContactFragment contactFragment;
    public static ConversationFragment conversationFragment;
    public static PluginFragment pluginFragment;

    /**
     * 传入position 返回对应的fragment对象
     * @param position
     * @return
     */
    public static BaseFragment getFragment(int position){
        switch ( position){
            case 0:
                if(conversationFragment == null){
                    conversationFragment = new ConversationFragment();
                }
                return  conversationFragment;

            case 1:
                if(contactFragment == null){
                    contactFragment = new ContactFragment();
                }
                return contactFragment;
            case 2:
                if(pluginFragment == null){
                    pluginFragment = new PluginFragment();
                }
                return pluginFragment;
        }
        return contactFragment;
    }
}
